package com.demo.day719;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
@Auther: MFM
@Date: 2021/7/19 - 07 - 19 - 18:50 
@version: 1.0
*/

public class Test {
    public static long getDay(String birthday) throws ParseException {

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date birth = dateFormat.parse(birthday);
        Date current = new Date();
        long dayNum = current.getTime() - birth.getTime();

        return dayNum/1000/60/60/24;
    }

    public static void main(String[] args) throws ParseException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入出生日期，按照yyyy-MM-dd输入，例如：2002-05-29");
        String bir = scanner.next();
        System.out.println("一共活了"+getDay(bir)+"天");
    }
}
